package com.booking.action;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Repository;

import com.booking.bean.Users;
import com.booking.service.UserService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

@Controller
public class LoginAction extends ActionSupport implements ModelDriven<Users>{
	
	@Autowired
	private Users user; 
	 
	@Autowired
    private UserService service;
	 
	@Override
	public Users getModel() {
		return user;
	} 
	
	//登录方法
	public String Login() throws Exception{ 
		
		String loginError;

    	System.out.println("登录。。。。");
    	System.out.println(user.toString());
    	//service.saveUser(user);
    	Users loginUser = service.login(user);
    	
		if(loginUser == null){
			//登录失败
		//	this.addActionError("用户名或密码错误");
			ActionContext.getContext().put("loginError","用户名或密码不正确");
			return "input";
		}else{
			//登录成功
			ActionContext.getContext().getSession().put("loginUser",loginUser);
			return "frame";
		}
	  }
}
